#pragma once

#include "common.h"
#include "ntdproto.h"
//#include "speedmeasure.h"

class TCPServer : public NtdProtoParser
{
public:
	TCPServer();
	virtual ~TCPServer();
	bool Listen(int port);
	void Stop();
	void OnIncomingConnection(evutil_socket_t fd, struct sockaddr *sa, int socklen);
	void OnRead();
	void OnWrite();
	void OnError(int err);
	void OnClose();

	virtual void HandleProtoData(NtdProtoData * proto, void* pContext);

private:
	struct evconnlistener * m_listener;
	struct bufferevent * m_bev;
	NtdProtoFeedback m_feedback;

	//SpeedMeasure m_sm;
};